package com.boarsoft.dao.sharding.oceanbase.autoconfigure;

import com.boarsoft.dao.sharding.oceanbase.executor.DbpSqlRouteExecutor;
import com.boarsoft.dao.sharding.oceanbase.mybatis.inspcetor.DbpRouteConditionInspector;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
public class DbpRouteAutoConfiguration {

    @Resource
    private SqlSessionFactory sqlSessionFactory;

    @PostConstruct
    public void addInterceptor() {
        this.sqlSessionFactory.getConfiguration().addInterceptor(new DbpRouteConditionInspector());
    }

    @Bean
    public DbpSqlRouteExecutor dbpSqlRouteExecutor(){
        return new DbpSqlRouteExecutor();
    }
}
